package com.sinoglobal.ningxia.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.beans.CommentInfoVo;

/**
 * @author qiwx
 * @createdate 2014-6-28 下午1:27:13
 * @Description: 没有图片的评论
 */
public class NoImgCommentAdapter extends BaseAdapter {

	private ArrayList<CommentInfoVo> commentList;
	private LayoutInflater layoutInflater;

	public NoImgCommentAdapter(Context context, ArrayList<CommentInfoVo> commentList) {
		if(commentList==null){
			commentList=new ArrayList<CommentInfoVo>();
		}
		this.commentList = commentList;
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public void addData(ArrayList<CommentInfoVo> commentList) {
		if(commentList!=null&&!commentList.isEmpty()){
			this.commentList.addAll(commentList);
			this.notifyDataSetChanged();
		}
	}
	public void clearData() {
		if(commentList!=null){
			commentList.clear();
			notifyDataSetChanged();
		}
	}
    
	@Override
	public int getCount() {
		//Auto-generated method stub
		return commentList==null?0:commentList.size();
	}

	@Override
	public Object getItem(int position) {
		//Auto-generated method stub
		return commentList.get(position);
	}

	@Override
	public long getItemId(int position) {
		//Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		//Auto-generated method stub
		ViewHolder viewholer;
		if (convertView == null) {
			viewholer = new ViewHolder();
			convertView = layoutInflater.inflate(R.layout.news_comment_list_item, null);
			viewholer.userName = (TextView) convertView.findViewById(R.id.userName);
			viewholer.content = (TextView) convertView.findViewById(R.id.commentContent);
			viewholer.time = (TextView) convertView.findViewById(R.id.commentTime);
			convertView.setTag(viewholer);
		} else {
			viewholer = (ViewHolder) convertView.getTag();
		}
		CommentInfoVo bean = commentList.get(position);
		viewholer.userName.setText(bean.getNickname());
		viewholer.content.setText(bean.getContent());
		viewholer.time.setText(bean.getCreate_time());
		return convertView;
	}

	class ViewHolder {
		TextView userName;
		TextView content;
		TextView time;
	}

}
